// src/router/index.ts
import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/login",
      name: "Login",
      component: () => import("../views/Login.vue"),
      meta: { title: '登录' }
    },
    {
      path: "/register",
      name: "Register",
      component: () => import("../views/register.vue"),
      meta: { title: '注册' }
    },
    // 学生路由
    {
      path: "/student",
      name: "StudentLayout",
      component: () => import("../views/student/StudentLayout.vue"),
      redirect: "/student/home",
      meta: { title: '学生系统' },
      children: [
        {
          path: "home",
          name: "StudentHome",
          component: () => import("../views/student/Home.vue"),
          meta: { 
            title: '学生首页',
            breadcrumb: [
              { title: '学生系统', path: '/student/home' },
              { title: '学生首页' }
            ]
          }
        },
        {
          path: "exam-management",
          name: "StudentExamManagement",
          component: () => import("../views/student/ExamManagement.vue"),
          meta: { 
            title: '考试管理',
            breadcrumb: [
              { title: '学生系统', path: '/student/home' },
              { title: '考试管理' }
            ]
          }
        },
        {
          path: "exam/:id",
          name: "StudentExam",
          component: () => import("../views/student/ExamPage.vue"),
          meta: { 
            title: '考试',
            breadcrumb: [
              { title: '学生系统', path: '/student/home' },
              { title: '考试管理', path: '/student/exam-management' },
              { title: '考试' }
            ]
          }
        },
        {
          path: "exam-details",
          name: "StudentExamDetails",
          component: () => import("../views/student/ExamDetails.vue"),
          meta: { 
            title: '考试详情',
            breadcrumb: [
              { title: '学生系统', path: '/student/home' },
              { title: '考试管理', path: '/student/exam-management' },
              { title: '考试详情' }
            ]
          }
        },
        {
          path: "ranking",
          name: "StudentRanking",
          component: () => import("../views/student/Ranking.vue"),
          meta: { 
            title: '排行榜',
            breadcrumb: [
              { title: '学生系统', path: '/student/home' },
              { title: '排行榜' }
            ]
          }
        },
        {
          path: "profile",
          name: "StudentProfile",
          component: () => import("../views/student/Profile.vue"),
          meta: { 
            title: '个人信息',
            breadcrumb: [
              { title: '学生系统', path: '/student/home' },
              { title: '个人信息' }
            ]
          }
        }
      ]
    },
    // 主框架路由
    {
      path: "/main",
      name: "MainIndex",
      component: () => import("../views/MainIndex.vue"),
      redirect: "/main/index", 
      meta: { title: '考试系统' },
      children: [
        // 首页
        {
          path: "index",
          name: "Home",
          component: () => import("../views/Home.vue"),
          meta: { 
            title: '首页',
            breadcrumb: [
              { title: '考试系统', path: '/main/index' },
              { title: '首页' }
            ]
          }
        },
        // 试卷库
        {
          path: "paper",
          name: "Paper",
          redirect: "/main/paper/create",
          meta: { title: '试卷库' },
          children: [
            {
              path: "create",
              name: "PaperCreate",
              component: () => import("../views/paper/CreatePaper.vue"),
              meta: { 
                title: '创建试卷',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '试卷库', path: '/main/paper/create' },
                  { title: '创建试卷' }
                ]
              }
            },
            {
              path: "list",
              name: "PaperList",
              component: () => import("../views/paper/PaperList.vue"),
              meta: { 
                title: '试卷列表',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '试卷库', path: '/main/paper/list' },
                  { title: '试卷列表' }
                ]
              }
            },
          ]
        },
        // 试题库
        {
          path: "question",
          name: "Question",
          redirect: "/main/question/bank",
          meta: { title: '试题库' },
          children: [
            {
              path: "bank",
              name: "QuestionBank",
              component: () => import("../views/question/QuestionBank.vue"),
              meta: { 
                title: '题库管理',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '试题库', path: '/main/question/bank' },
                  { title: '题库管理' }
                ]
              }
            },
            {
              path: "manage",
              name: "QuestionManage",
              component: () => import("../views/question/QuestionManage.vue"),
              meta: { 
                title: '试题管理',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '试题库', path: '/main/question/bank' },
                  { title: '试题管理' }
                ]
              }
            },
            {
              path: "preview",
              name: "QuestionPreview",
              component: () => import("../views/question/QuestionPreview.vue"),
              meta: { 
                title: '题库预览',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '试题库', path: '/main/question/bank' },
                  { title: '题库管理', path: '/main/question/bank' },
                  { title: '题库预览' }
                ]
              }
            }
          ]
        },
        // 学习库
        {
          path: "learn",
          name: "Learn",
          redirect: "/main/learn/manage",
          meta: { title: '学习库' },
          children: [
            {
              path: "manage",
              name: "LearnManage",
              component: () => import("../views/learn/LearnManage.vue"),
              meta: { 
                title: '学习管理',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '学习库', path: '/main/learn/manage' },
                  { title: '学习管理' }
                ]
              }
            },
            {
              path: "message",
              name: "GroupMessage",
              component: () => import("../views/learn/GroupMessage.vue"),
              meta: { 
                title: '群发消息',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '学习库', path: '/main/learn/manage' },
                  { title: '群发消息' }
                ]
              }
            }
          ]
        },
        // 保留的个人中心
        {
          path: "self",
          name: "Self",
          redirect: "/main/self/pwd",
          meta: { title: '个人中心' },
          children: [
            {
              path: "pwd",
              name: "EditPwd",
              component: () => import("../views/self/editPwd.vue"),
              meta: { 
                title: '修改密码',
                breadcrumb: [
                  { title: '考试系统', path: '/main/index' },
                  { title: '个人中心', path: '/main/self/pwd' },
                  { title: '修改密码' }
                ]
              }
            }
          ]
        }
      ]
    },
  ]
});

export default router;